package com.rain.bee.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * ribbon
 *@Title:  
 *@Description:  
 *@Author: leaf  
 *@Since:2019年2月18日  
 *@Version:1.1.0
 */
@RestController
public class IndexController {

	@Autowired
	private RestTemplate restTemplate;

	@Autowired
	private LoadBalancerClient loadBalancerClient;

	@GetMapping("index")
	public String index() {

		ServiceInstance service = loadBalancerClient.choose("microservice-provider-bee");
		String result = service.getServiceId() + ":" + service.getHost() + ":" + service.getPort();

		return result;
	}
	
	@GetMapping("index1/{id}")
	public String index1(@PathVariable String id) {

		String result = restTemplate.getForObject("http://microservice-provider-bee/test/" + id, String.class);

		return result;
	}
	
}
